﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using StockMatch.Service.Entity;
using Titan;

namespace StockMatch.Service.Test
{
    [TestClass]
    public class UserServiceTest
    {
        UserService userserice = new UserService();
        User user = new User()
        {
            UserName = "King",
            UserTrueName = "张婷婷",
            UserPassword = "123",
            Phone = "13265454584",
            SafeGrade = 1,
            TotalAmount = 300000,
            Province = 5,
            City =2
        };

        [TestMethod]
        public void Insert()
        {
            Assert.AreEqual(true, userserice.Insert(user));
        }


        [TestMethod]
        public void Update()
        {
            user.UserId = 2;
            user.UserPassword = "123456";
            var updateperporty = new PropertyExpression[] {
                User_.UserPassword
            };

            Assert.AreEqual(true, userserice.Update(user, updateperporty));
        }

        [TestMethod]
        public void Delete()
        {
            Assert.AreEqual(true, userserice.Delete(3));
        }


        [TestMethod]
        public void GetUser()
        {
            Assert.AreEqual("zhangsan", userserice.GetUser(2).UserName);
        }

        [TestMethod]
        public void GetUserbyquery()
        {
            var query = new QueryExpression();
            query.EntityType = typeof(User);
            query.Select(User_.UserId)
                .Where(User_.UserName.TLike("zhang"));
            query.ReturnMatchedCount = true;
            var users = new Users();

            Assert.AreEqual(1, userserice.GetUsers(query).TotalCount);
        }
    }
}
